package com.skycong.hello77.activity.common.viewbinder;

import android.content.Context;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.inputmethod.InputMethodManager;

import org.robobinding.ViewBinder;
import org.robobinding.binder.BinderFactory;


/**
 * Created by Kiki on 2018/5/9.
 */

public abstract class AbstractActivity extends FragmentActivity {
    private Object mViewModel;
    public View initializeContentView(int layoutId,Object presentationModel){
        ViewBinder viewBinder = createViewBinder();
        View rootView = viewBinder.inflateAndBind(layoutId,presentationModel);
        setContentView(rootView);
        mViewModel = presentationModel;
        return rootView;
    }

    protected  ViewBinder createViewBinder(){
        BinderFactory binderFactory = getReusableBinderFactory();
        return binderFactory.createViewBinder(this);
    }

    private BinderFactory getReusableBinderFactory() {
       BinderFactory binderFactory = ViewBinderUtil.getReusableBinderFactory();
       return binderFactory;
    }
    public Context getContext(){return this;}
    /**
     * 关闭软键盘
     */
    public void closeKeyboard(){
        View view = getWindow().peekDecorView();
        if(view != null){
            InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(),0);
        }
    }
}
